#! /bin/bash

str="hello"

# if [ $str = "hello" ];then
#     echo "yes"
# fi

# 字符串比较
# if [ $str == "hello" ];then
#     echo "yes"
# else
#     echo "no"
# fi

# 数值比较
# if [ 10 -gt 20 ];then
#     echo "yes"
# else
#     echo "no"
# fi

# 数值比较
# if ((10 > 20));then
#     echo "yes"
# else
#     echo "no"
# fi

# 数值比较
# read val1 val2
# if [ $val1 -gt $val2 ];then
#     echo $val1
# else
#     echo $val2
# fi


# 数值比较
# read val1 val2
# if (($val1 > $val2));then
#     echo $val1
# else
#     echo $val2
# fi


# 字符串比较
# if [ -z "hello" ];then
#     echo "true"
# else
#     echo "false"
# fi

# 文件
# if [ -s "hello.txt" ];then
#     echo "true"
# else
#     echo "false"
# fi

# [[ 支持模式匹配 ]]   []是 test的简写
if [ 10 -gt 20 ] && [[ "hello.log" == *.log ]] ;then
    echo "true"
else
    echo "false"
fi

<<!
逻辑运算符
-a  and
-o  or
!  not

字符串比较
-z
-n

数值比较
-eq
-ne
-gt
-ge
-lt
-le

文件
-e 是否存在
-f 是否普通文件
-d 是否目录
-s 文件大小是否大于0
!

# 判断输入数值是奇数偶数
read -p "input num:" val 
# if [ $(($val % 2)) -eq 1 ];then
if [ `expr $val % 2` -eq 1 ];then
    echo "奇数"
else
    echo "偶数"
fi


# 读取文件内容
read -p "input filename:" val
if [ -e $val ];then
    echo "存在"
    if [ -f $val ];then
        echo "普通文件"
        if [ -s $val ];then
            echo "文件大小大于0"
            cat $val
        else
            echo "文件大小小于0"
        fi
    elif [ -d $val ];then
        echo "目录"
    fi
else
    echo "不存在"
fi


